<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="协调人组标识" prop="authorizeGroup">
        <el-input
          v-model="queryParams.authorizeGroup"
          placeholder="请输入协调人组标识"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['coordinatorGroup:coordinatorgroup:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['coordinatorGroup:coordinatorgroup:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['coordinatorGroup:coordinatorgroup:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['coordinatorGroup:coordinatorgroup:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="协调人组标识" prop="authorizeGroup" width="120" />
      <el-table-column label="协调人组" prop="description" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="客户订单号" prop="orderNo" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="销售报价号" prop="quotationNo" width="100" />
      <el-table-column label="服务报价号" prop="distOrderPrefix" width="100" />
      <el-table-column label="订单号" prop="distOrderNo" width="100" />
      <el-table-column label="服务报价单号" prop="serviceQuotationNo" width="100" />
      <el-table-column label="允许数字序列有错" prop="allowLapsesInNumbers" width="100" />
      <el-table-column label="时间" prop="rowversion" width="100" />
      <el-table-column label="排键" prop="rowkey" width="100" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['coordinatorGroup:coordinatorgroup:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['coordinatorGroup:coordinatorgroup:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="协调人组标识" prop="authorizeGroup">
          <el-input v-model="form.authorizeGroup" placeholder="请输入协调人组标识" :disabled="disable" />
        </el-form-item>
        <el-form-item label="协调人组" prop="description">
          <el-input v-model.number="form.description" placeholder="请输入协调人组" />
        </el-form-item>
        <el-form-item label="客户订单号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入客户订单号" />
        </el-form-item>
        <el-form-item label="销售报价号" prop="quotationNo">
          <el-input v-model.number="form.quotationNo" placeholder="请输入销售报价号" />
        </el-form-item>
        <el-form-item label="服务报价号" prop="distOrderPrefix">
          <el-input v-model="form.distOrderPrefix" placeholder="请输入服务报价号" />
        </el-form-item>
        <el-form-item label="订单号" prop="distOrderNo">
          <el-input v-model="form.distOrderNo" placeholder="请输入订单号"></el-input>
        </el-form-item>
        <el-form-item label="服务报价单号" prop="serviceQuotationNo">
          <el-input v-model="form.serviceQuotationNo" placeholder="请输入服务报价单号"></el-input>
        </el-form-item>
        <el-form-item label="允许数字序列有错" prop="allowLapsesInNumbers">
          <el-input v-model="form.allowLapsesInNumbers"  placeholder="请输入允许数字序列有错"></el-input>
        </el-form-item>
        <el-form-item label="时间" prop="rowversion">
          <el-input v-model="form.rowversion"  placeholder="请输入时间"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
<!--    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>-->
<!--      <el-upload-->
<!--        ref="upload"-->
<!--        :limit="1"-->
<!--        accept=".xlsx, .xls"-->
<!--        :headers="upload.headers"-->
<!--        :action="upload.url + '?updateSupport=' + upload.updateSupport"-->
<!--        :disabled="upload.isUploading"-->
<!--        :on-progress="handleFileUploadProgress"-->
<!--        :on-success="handleFileSuccess"-->
<!--        :auto-upload="false"-->
<!--        drag-->
<!--      >-->
<!--        <i class="el-icon-upload"></i>-->
<!--        <div class="el-upload__text">-->
<!--          将文件拖到此处，或-->
<!--          <em>点击上传</em>-->
<!--        </div>-->
<!--        <div class="el-upload__tip" slot="tip">-->
<!--          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
<!--          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>-->
<!--        </div>-->
<!--        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>-->
<!--      </el-upload>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitFileForm">确 定</el-button>-->
<!--        <el-button @click="upload.open = false">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
  import {exportCoordinator,getCoordinator,updateCoordinator,addCoordinator,deleCoordinator,listCoordinator} from "@/api/erp/coordinatorgroup/coordinatorgroup";

  export default {
    name: "coordinatorgroup",
    data() {
      return {
        //接收到的查询条件
        unitCode:"",
        //判断是查询弹窗还是新增或修改弹窗(未用到)
        isselectOraddAndEi:false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // isounitIds: [],
        //
        // handleSelectionIsounitChange(selection) {
        //   this.isounitIds = selection.map(item => item.transportUnitTypeId)
        //   this.isounitSingle = selection.length!=1
        //   this.isounitMultiple = !selection.length
        // },



        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 条件总条数
        isounitTotal :0,
        // 角色表格数据
        roleList: [],

        // 运输单位类型查询条件
        isounitList: [],
        // 弹出层标题
        title: "",
        disable:true,
        // 条件弹出层标题
        isounitTitle:"",
        // 是否显示弹出层
        open: false,
        // 是否显示条件弹出层
        isounitOpen:false,
        // 是否显示弹出层（数据权限）
        openDataScope: false,
        menuExpand: false,
        menuNodeAll: false,
        deptExpand: true,
        deptNodeAll: false,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],

        //导出参数
        exparams: {
          ids:[]
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          authorizeGroup: undefined,
          description: undefined,
          orderNo: undefined,
          quotationNo: undefined,
          distOrderPrefix: undefined,
          distOrderNo: undefined,
          serviceQuotationNo: undefined,
          allowLapsesInNumbers: undefined,
          rowversion: undefined,
          rowkey: undefined
        },
        // 查询参数
        isounitQueryParams: {
          pageNum: 1,
          pageSize: 10,
          authorizeGroup: undefined
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 表单校验
        rules: {
          authorizeGroup: [
            { required: true, message: "协调人组标识不能为空", trigger: "blur" }
          ]
        }
      };
    },
    created() {},
    mounted() {
      this.getList();
    },
    methods: {
      getList(){
        listCoordinator(this.queryParams)
          .then((response) => {
            this.loading = false;
            this.roleList = response.rows;
            this.total = response.total;
          })
          .catch((error) => {
            alert("失败");
          });
      },

      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form={}
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.authorizeGroup)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      handleSelectionIsounitChange(selection) {
        this.isounitIds = selection.map(item => item.authorizeGroup)
        this.isounitSingle = selection.length!=1
        this.isounitMultiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.disable = false;
        this.reset();
        this.open = true;
        this.title = "添加协调人组信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.disabled = true;
        this.reset();
        const routeId = row.authorizeGroup || this.ids;
        getCoordinator(routeId).then((response) => {
          this.form = response.data;
          this.open = true;
          this.title = "修改协调人组";
        });
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            if (this.title === "修改协调人组") {
              updateCoordinator(this.form).then((response) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addCoordinator(this.form).then((response) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.authorizeGroup || this.ids;
        this.$confirm(
          '是否确认协调人组标识为"' + ids + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function() {
          return deleCoordinator(ids);
        })
          .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },

      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm("是否确认导出所有交货路线数据项?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return exportCoordinator(queryParams);
          })
          .then((response) => {
            this.download(response.msg);
          });
      }
    }
  };
</script>
